home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Pascal / System / Adjust Window FKEY / adjwindfkey < prev   
Encoding:
Text File  |  1994-04-21  |  6.6 KB  |  254 lines  |  [TEXT/R*ch]

  1. { Adjust Window Fkey                                                 }
  2. { A FKEY that allows you to specify the size and position of a window}
  3. { written by Matthew Xavier Mora mxmora@unix.sri.com 2-28-94         }
  4. { Copyright 1994 MXM Designs                                         }
  5.  
  6. unit AdjustWindow;
  7.  
  8. interface
  9. {$IFC THINK_PASCAL=FALSE}
  10.   uses
  11.     Windows, TextEdit;
  12. {$ENDC}
  13.   procedure main;
  14.  
  15. implementation
  16.  
  17. { ----------------------------------------------------------------------}
  18.   procedure main;
  19. { ----------------------------------------------------------------------}
  20.  
  21.     var
  22.       w: WindowPtr;
  23.       r: Rect;
  24.       te: array[1..4] of TeHandle;
  25.       textlabel: array[1..4] of string[8];
  26.       curW: WindowPtr;
  27.       ok: ControlHandle;
  28.       notDone: Boolean;
  29.       evt: EventRecord;
  30.       curTE: integer;
  31.       ch: char;
  32.       i: integer;
  33.       temp: str255;
  34.  
  35. { ----------------------------------------------------------------------}
  36.     function abs (x: integer): integer;
  37. { ----------------------------------------------------------------------}
  38.     begin
  39.       if x < 0 then
  40.         x := x * (-1);
  41.       abs := x;
  42.     end;
  43. { ----------------------------------------------------------------------}
  44.     procedure AdjustWindowParams;
  45. { ----------------------------------------------------------------------}
  46.       var
  47.         t, l, b, r: longint;
  48.     begin
  49.  
  50.       GetIText(te[1]^^.hText, temp);
  51.       StringToNum(temp, t);
  52.  
  53.       GetIText(te[2]^^.hText, temp);
  54.       StringToNum(temp, l);
  55.  
  56.       GetIText(te[3]^^.hText, temp);
  57.       StringToNum(temp, b);
  58.  
  59.       GetIText(te[4]^^.hText, temp);
  60.       StringToNum(temp, r);
  61.  
  62.       CloseWindow(w);
  63.  
  64.       MoveWindow(curW, l, t, true);
  65.       SizeWindow(curW, abs(r - l), abs(b - t), true);
  66.     end;
  67.  
  68. { ----------------------------------------------------------------------}
  69.     procedure DoMouse;
  70. { ----------------------------------------------------------------------}
  71.       var
  72.         part: integer;
  73.         w: WindowPtr;
  74.         ch: ControlHandle;
  75.         p: Point;
  76.         r: Rect;
  77.         i: integer;
  78.     begin
  79.       p := evt.where;
  80.       part := FindWindow(p, w);
  81.       case part of
  82.         inContent: 
  83.           begin
  84.             GlobalToLocal(p);
  85.             part := FindControl(p, w, ch);
  86.             if ch <> nil then
  87.               begin
  88.                 if TrackControl(ch, p, nil) <> 0 then
  89.                   notDone := false;
  90.               end;
  91.             for i := 1 to 4 do
  92.               begin
  93.                 r := te[i]^^.viewRect;
  94.                 if PtInRect(p, r) then
  95.                   begin
  96.                     TEDeactivate(te[curTE]);
  97.                     curTe := i;
  98.                     TEActivate(te[curTE]);
  99.                     TEClick(p, false, te[curTE]);
  100.                   end;
  101.               end;
  102.  
  103.           end;
  104.         otherwise
  105.           ;
  106.  
  107.       end;
  108.  
  109.  
  110.     end;
  111. { ----------------------------------------------------------------------}
  112.     procedure HandleKey;
  113. { ----------------------------------------------------------------------}
  114.     begin
  115.       ch := CHR(BAnd(evt.message, charCodeMask));
  116.       if ch = chr(9) then
  117.         begin
  118.           TEDeactivate(te[curTE]);
  119.           curTE := CurTE + 1;
  120.           if curTE > 4 then
  121.             curTE := 1;
  122.           TEActivate(te[curTE]);
  123.         end
  124.       else
  125.         TEKey(ch, te[curTE]);
  126.     end;
  127. { ----------------------------------------------------------------------}
  128.     procedure HandleUpdate;
  129. { ----------------------------------------------------------------------}
  130.       var
  131.         i: integer;
  132.         wp: WindowPtr;
  133.     begin
  134.       wp := WindowPtr(evt.message);
  135.       if (wp = w) then
  136.         begin
  137.           r := w^.portRect;
  138.           SetPort(w);
  139.           BeginUpdate(w);
  140.  
  141.           Moveto(10, 18);
  142.           DrawString('Adjust Window Fkey by Matt Mora vers 1.0');
  143.           UpdateControls(w, w^.visRgn);
  144.           for i := 1 to 4 do
  145.             begin
  146.               TEUpdate(r, te[i]);
  147.               r := te[i]^^.destRect;
  148.               InsetRect(r, -2, -2);
  149.               FrameRect(r);
  150.               MoveTo(r.left - 52, r.bottom - 4);
  151.               DrawString(textlabel[i]);
  152.             end;
  153.           EndUpdate(w);
  154.         end;
  155.       if (wp = curW) then
  156.         begin
  157.  
  158.           BeginUpdate(curW);
  159.  
  160.           EndUpdate(curW);
  161.         end;
  162.  
  163.     end;
  164.  
  165. { ----------------------------------------------------------------------}
  166.     procedure Terminate;
  167. { ----------------------------------------------------------------------}
  168.  
  169.     begin
  170.       CloseWindow(w);
  171.       CloseWindow(curW);
  172.  
  173.     end;
  174.   begin
  175.  
  176. {$IFC DEBUG=FALSE}
  177.     curW := FrontWindow;
  178. {$ELSEC}
  179.     SetRect(r, 20, 40, 400, 280);
  180.     curW := NewWindow(nil, r, 'Adjust Window', true, documentProc, 
  181.                       WindowPtr(-1), false, 0);
  182.  
  183. {$ENDC}
  184.  
  185.     if curW <> nil then
  186.       begin
  187.         textlabel[1] := 'Top:';
  188.         textlabel[2] := 'Left:';
  189.         textlabel[3] := 'Bottom:';
  190.         textlabel[4] := 'Right:';
  191.  
  192.         SetRect(r, 50, 100, 400, 280);
  193.         w := NewWindow(nil, r, 'Adjust Window', true, dBoxProc, 
  194.                        WindowPtr(-1), false, 0);
  195.         SetPort(w);
  196.         ShowWindow(w);
  197.         SetRect(r, 250, 120, 300, 140);
  198.         ok := NewControl(w, r, 'OK', true, 0, 0, 0, 0, 0);
  199.         SetRect(r, 100, 30, 150, 48);
  200.         te[1] := TENew(r, r);
  201.  
  202.         OffsetRect(r, 0, 28);
  203.         te[2] := TENew(r, r);
  204.  
  205.         OffsetRect(r, 0, 28);
  206.         te[3] := TENew(r, r);
  207.  
  208.         OffsetRect(r, 0, 28);
  209.         te[4] := TENew(r, r);
  210.         notDone := true;
  211.         curTE := 1;
  212.  
  213.         TEActivate(te[curTE]);
  214.         r := curW^.portRect;
  215.         SetPort(curW);
  216.         LocalToGlobal(r.topleft);
  217.         LocalToGlobal(r.botRight);
  218.         SetPort(w);
  219.         NumToString(r.top, temp);
  220.         TEInsert(ptr(ord(@temp) + 1), longint(temp[0]), te[1]);
  221.         NumToString(r.left, temp);
  222.         TEInsert(ptr(ord(@temp) + 1), longint(temp[0]), te[2]);
  223.         NumToString(r.bottom, temp);
  224.         TEInsert(ptr(ord(@temp) + 1), longint(temp[0]), te[3]);
  225.         NumToString(r.right, temp);
  226.         TEInsert(ptr(ord(@temp) + 1), longint(temp[0]), te[4]);
  227.  
  228.         while notDone do
  229.           begin
  230.             if WaitNextEvent(everyEvent, evt, 100, nil) then
  231.               begin
  232.                 case evt.what of
  233.                   mouseDown: 
  234.                     DoMouse;
  235.                   keyDown, autoKey: 
  236.                     HandleKey;
  237.                   updateEvt: 
  238.                     HandleUpdate;
  239.                   otherwise
  240.                     ;
  241.                 end;
  242.               end
  243.             else
  244.               begin
  245.                 TEIdle(te[curTE]);
  246.               end;
  247.           end;
  248.       end;
  249.     AdjustWindowParams;
  250. {    Terminate;}
  251.   end;
  252.  
  253. end.
  254.